package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.properties.TcConfig;
import cn.stylefeng.guns.sys.core.util.ConvertUtil;
import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.core.util.ExcelFormatUtil;
import cn.stylefeng.guns.sys.modular.system.controller.BaseFrontController;
import cn.stylefeng.guns.sys.modular.system.entity.DsstoreBillDelivery;
import cn.stylefeng.guns.sys.modular.system.mapper.DsstoreBillDeliveryMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.DsstoreBillDeliveryParam;
import cn.stylefeng.guns.sys.modular.system.model.result.DsstoreBillBusType;
import cn.stylefeng.guns.sys.modular.system.model.result.DsstoreBillDeliveryResult;
import cn.stylefeng.guns.sys.modular.system.service.DsstoreBillDeliveryService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jiangge
 * @since 2021-07-12
 */
@Service
public class DsstoreBillDeliveryServiceImpl extends ServiceImpl<DsstoreBillDeliveryMapper, DsstoreBillDelivery> implements DsstoreBillDeliveryService {
    private Logger logger = LoggerFactory.getLogger(DsstoreBillDeliveryServiceImpl.class);
    private RestTemplate restTemplate = new RestTemplate();

    @Autowired
    private TcConfig tcConfig;

    @Override
    public void add(DsstoreBillDeliveryParam param) {
        DsstoreBillDelivery entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(DsstoreBillDeliveryParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(DsstoreBillDeliveryParam param) {
        DsstoreBillDelivery oldEntity = getOldEntity(param);
        DsstoreBillDelivery newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public DsstoreBillDeliveryResult findBySpec(DsstoreBillDeliveryParam param) {
        return null;
    }

    @Override
    public List<DsstoreBillDeliveryResult> findListBySpec(DsstoreBillDeliveryParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(DsstoreBillDeliveryParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(DsstoreBillDeliveryParam param) {
        return param.getStoreBillDtid();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private DsstoreBillDelivery getOldEntity(DsstoreBillDeliveryParam param) {
        return this.getById(getKey(param));
    }

    private DsstoreBillDelivery getEntity(DsstoreBillDeliveryParam param) {
        DsstoreBillDelivery entity = new DsstoreBillDelivery();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void initDsstoreBillData(List<String> dateList) {


        Map<String, String> monthMap = new HashMap<>();
        if (CollectionUtil.isNotEmpty(dateList)) {
            for (String month : dateList) {
                monthMap.put(month, month);
            }
        }

        List<String> dateParamList = new ArrayList<>();
        //业务日期
        dateParamList.add("busdate");
        //审核日期-1.业务日期数据 2.修改的数据 3.之前的数据插入
//        dateParamList.add("auditDate");

        List<String> billTypeList = new ArrayList<>();
        billTypeList.add("0430_0010_0400");
        billTypeList.add("0430_0020_0100");

        //某月底可能无法走接口录入数据，此时需要先执行删除语句，然后将业务json数据录入、审核日期对应json数据录入
        for (String dateParam : dateParamList) {
            for (String day : dateList) {
                //业务日期当天的数据先删除掉，改单删单可能存在垃圾数据
                if ("busdate".equals(dateParam)) {
                    this.baseMapper.deleteDataByDay(day);
                }
//                if (dateParam.equals("auditDate")) {
//                    this.baseMapper.deleteDataByDay2(day);
//                }
            }
        }

        for (String dateParam : dateParamList) {
            for (String day : dateList) {
                for (String billType : billTypeList) {
                    String url = "http://btyjt.c3.fxscm.net/cldpoint/getDsstorebill.do?ent=ENT7617&username=" + tcConfig.getUsername() + "&password=" + tcConfig.getPassword() + "&" + dateParam + "=" + day + "&billTypeId=" + billType;
                    String content = restTemplate.getForObject(url, String.class);
                    JSONObject jsonObjectResult = JSON.parseObject(content);
                    JSONArray jsonArray = jsonObjectResult.getJSONArray("data");

                    /**
                     * ShopCode    ShopName	ItemSmallClassName  ItemName
                     * 没有店名查询的的是所有的店,把获取到的数据取出来便利 然后挨个插入到表中
                     */
                    JSONObject jsonObject;

                    for (int i = 0; i < jsonArray.size(); i++) {
                        //把所有 ItemSmallClassName 为 酱料 的添加到list中
                        jsonObject = jsonArray.getJSONObject(i);
                        List<String> type1 = Lists.newLinkedList();
                        type1.add("中心统配出库");
                        type1.add("中心统配返库");
                        //目前只用到4个品项
                        List<String> itemCodeList = Lists.newLinkedList();
                        itemCodeList.add("1104039");
                        itemCodeList.add("1104072");
                        itemCodeList.add("1000848");
                        itemCodeList.add("1000840");

                        DsstoreBillBusType DsstoreBillBusType = new DsstoreBillBusType();
                        DsstoreBillBusType.setBillBusType(jsonObject.getOrDefault("BillBusType", "").toString());
                        DsstoreBillBusType.setBillType(jsonObject.getOrDefault("BillType", "").toString());

                        if (type1.contains(jsonObject.getOrDefault("BillType", ""))
                                && itemCodeList.contains(jsonObject.getOrDefault("ItemCode", ""))
                                && "山东配送中心".equals(jsonObject.getOrDefault("ShopName", "").toString())) {
                            DsstoreBillDelivery dsstoreBillRice = convertToDsstoreBillRice(jsonObject);

                            if (monthMap.get(DateUtil.getStrDate(dsstoreBillRice.getBusDate())) != null) {
                                //不存在增加
                                this.saveOrUpdate(dsstoreBillRice);
                            }

                        }
                    }
                }
            }
        }


    }

    @Override
    public LayuiPageInfo findPageByParam(DsstoreBillDeliveryParam param) {

        //TODO-1 获取查询结果
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageByParam(pageContext, param);
        List<DsstoreBillDeliveryResult> conutDataList = page.getRecords();

        //TODO-2 单位换算，最小单位换算为商务单位
//        if (CollectionUtil.isNotEmpty(conutDataList)) {
//            //获取所有品项的商务单位
//            List<ItemBusUnitParam> allItemBusUnitList = itemInterfaceService.getAllItemBusUnit();
//            Map<String, ItemBusUnitParam> unitMap = new HashMap<>();
//            for (ItemBusUnitParam itemBusUnitParam : allItemBusUnitList) {
//                unitMap.put(itemBusUnitParam.getItemCode(), itemBusUnitParam);
//            }
//
//            //换单位
//            for (DsstoreBillDeliveryResult dsstoreBill : conutDataList) {
//                BigDecimal itemBalanceAmount = dsstoreBill.getAmount();
//                //对应的商务单位数据
//                ItemBusUnitParam item = unitMap.get(dsstoreBill.getItemCode());
//                if(item!=null){
//                    //单位
//                    dsstoreBill.setBusUnit(item.getItemUnitName());
//                    //换算
//                    BigDecimal itemBalanceBusAmout = BigDecimal.ZERO;
//                    if (itemBalanceAmount != null && itemBalanceAmount.compareTo(BigDecimal.ZERO) != 0) {
//                        itemBalanceBusAmout = itemBalanceAmount.divide(item.getUnitRatio(), 6, BigDecimal.ROUND_UP);
//                    }
//                    dsstoreBill.setAmount(itemBalanceBusAmout);
//
//                    //计算单价
//                    dsstoreBill.setUnitPrice(itemBalanceBusAmout.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:(dsstoreBill.getSaleMoney().divide(dsstoreBill.getAmount(), 6, BigDecimal.ROUND_UP)));
//                }
//            }
//        }


        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public DsstoreBillDeliveryResult getViewDataById(String id) {
        DsstoreBillDeliveryResult dsstoreBillDelivery = this.baseMapper.getViewDataById(id);
        return dsstoreBillDelivery;
    }

    @Override
    public List<DsstoreBillDeliveryResult> getViewDataListById(List<String> ids) {
        List<DsstoreBillDeliveryResult> list = this.baseMapper.getViewDataListById(ids);
        return list;

    }

    @Override
    public ResponseEntity<byte[]> exportExcel(HttpServletRequest request, HttpServletResponse response, DsstoreBillDeliveryParam param) {
        try {
            logger.info(">>>>>>>>>>连锁配送-开始导出excel>>>>>>>>>>");
            BaseFrontController baseFrontController = new BaseFrontController();
            //TODO-1 获取查询结果
            List<DsstoreBillDeliveryResult> resultList = this.baseMapper.findListByParam(param);

            return baseFrontController.buildResponseEntity(export(resultList, param), "连锁配送台账表-发货统计表-财务报表 (业务日期:" + param.getDateStr() + ")" + ".xls");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(">>>>>>>>>>连锁配送-导出excel 异常，原因为：" + e.getMessage());
        }
        return null;
    }

    private InputStream export(List<DsstoreBillDeliveryResult> list, DsstoreBillDeliveryParam param) {
        logger.info(">>>>>>>>>>>>>>>>>>>>开始进入导出方法>>>>>>>>>>");
        ByteArrayOutputStream output = null;
        InputStream inputStream1 = null;
        // 保留1000条数据在内存中
        SXSSFWorkbook wb = new SXSSFWorkbook(1000);
        SXSSFSheet sheet = wb.createSheet();
        // 设置报表头样式cell样式
        CellStyle header = ExcelFormatUtil.headSytle(wb);
        // 报表体样式
        CellStyle content = ExcelFormatUtil.contentStyle(wb);
        //TODO-2 每一列字段名
        String[] titles = new String[]{"序号", "配送中心名称", "门店名称", "业务类型", "品项类别名称", "品项编号", "品项名称", "品项规格", "单位", "数量", "含税配送单价", "含税配送金额", "卡号"};

        // 字段名所在表格的宽度，数量应与列字段名数量一致
        int[] ints = new int[]{5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000};

        //TODO-3 设置总标题内容，没有可略过
        //设置第一行标题：指定 4 个参数，起始行，结束行，起始列，结束列,
        int firstRow = 1;
        int lastRow = 1;
        int firstCol = 1;
        int lastCol = 13;
        SXSSFRow row1 = sheet.createRow(0);
        SXSSFCell cell0 = row1.createCell(0);
        CellRangeAddress regionFist = new CellRangeAddress(firstRow - 1, lastRow - 1, firstCol - 1, lastCol - 1);
        sheet.addMergedRegion(regionFist);
        //设置每一列的字段名
        cell0.setCellValue("连锁配送台账表-发货统计表-财务报表 (业务日期:" + param.getDateStr() + ")");
        cell0.setCellStyle(header);

        //TODO-4 设置内容标题
        //内容的标题所在行
        int concentitleStartRow = 2;
        //设置表头样式
        ExcelFormatUtil.initContentTitleEX(sheet, header, concentitleStartRow, titles, ints);
        logger.info(">>>>>>>>>>>>>>>>>>>>表头样式设置完成>>>>>>>>>>");

        //数量之和
        BigDecimal amountSum = BigDecimal.ZERO;
        //配送金额之和
        BigDecimal saleMoneySum = BigDecimal.ZERO;


        //TODO-5 从第contentStartRow行开始为内容数据
        int contentStartRow = concentitleStartRow + 1;
        if (list != null && list.size() > 0) {
            int hangInx = 1;
            logger.info(">>>>>>>>>>>>>>>>>>>>开始遍历数据组装单元格内容>>>>>>>>>>");
            for (int i = 0; i < list.size(); i++) {
                DsstoreBillDeliveryResult result = list.get(i);
                SXSSFRow row = sheet.createRow(contentStartRow + i - 1);
                int j = 0;

                // 序号
                SXSSFCell cell = row.createCell(j++);
                setCellVal(hangInx, content, cell);

                //配送中心名称
                cell = row.createCell(j++);
                setCellVal(result.getShopName(), content, cell);

                //门店名称
                cell = row.createCell(j++);
                setCellVal(result.getOtherSideName(), content, cell);

                //业务类型
                cell = row.createCell(j++);
                setCellVal(result.getBillBusType(), content, cell);

                //品项类别名称
                cell = row.createCell(j++);
                setCellVal(result.getItemSmallClassName(), content, cell);

                //品项编号
                cell = row.createCell(j++);
                setCellVal(result.getItemCode(), content, cell);

                //品项名称
                cell = row.createCell(j++);
                setCellVal(result.getItemName(), content, cell);

                //品项规格
                cell = row.createCell(j++);
                setCellVal(result.getItemSpec(), content, cell);

                //单位
                cell = row.createCell(j++);
                setCellVal(result.getItemUnitName(), content, cell);

                //数量
                cell = row.createCell(j++);
                setCellVal(result.getAmount() == null ? BigDecimal.ZERO : result.getAmount().setScale(4, BigDecimal.ROUND_UP), content, cell);

                amountSum = amountSum.add(result.getAmount() == null ? BigDecimal.ZERO : result.getAmount().setScale(4, BigDecimal.ROUND_UP));

                //含税配送单价
                cell = row.createCell(j++);
                setCellVal(result.getUnitPrice() == null ? BigDecimal.ZERO : result.getUnitPrice().setScale(4, BigDecimal.ROUND_UP), content, cell);

                //含税配送金额
                cell = row.createCell(j++);
                setCellVal(result.getSaleMoney() == null ? BigDecimal.ZERO : result.getSaleMoney().setScale(4, BigDecimal.ROUND_UP), content, cell);

                saleMoneySum = saleMoneySum.add(result.getSaleMoney() == null ? BigDecimal.ZERO : result.getSaleMoney().setScale(4, BigDecimal.ROUND_UP));

                //支付宝卡号
                cell = row.createCell(j++);
                setCellVal(result.getZfbkh() == null ? "" : result.getZfbkh(), content, cell);


                hangInx = hangInx + 1;

            }
            logger.info(">>>>>>>>>>>>>>>>>>>>结束遍历数据组装单元格内容>>>>>>>>>>");
        }

        int sumRowNum1 = contentStartRow + list.size();
        SXSSFRow rowSum = sheet.createRow(sumRowNum1 + 1);
        //制表人
        SXSSFCell cellSum0 = rowSum.createCell(0);
        cellSum0.setCellValue("总计");
        cellSum0.setCellStyle(content);

        SXSSFCell cellSum1 = rowSum.createCell(titles.length - 4);
        cellSum1.setCellValue(amountSum.toString());
        cellSum1.setCellStyle(content);
        //制表时间
        SXSSFCell cellSum2 = rowSum.createCell(titles.length - 2);
        cellSum2.setCellValue(saleMoneySum.toString());
        cellSum2.setCellStyle(content);


        //TODO 制表人、时间
        //所在行
        int sumRowNum2 = sumRowNum1 + 1;
        SXSSFRow rowEnd = sheet.createRow(sumRowNum2 + 1);
        //制表人
        SXSSFCell cellEnd0 = rowEnd.createCell(0);
        cellEnd0.setCellValue("制表人：" + LoginContextHolder.getContext().getUser().getName());
        //制表时间
        SXSSFCell cellEnd1 = rowEnd.createCell(titles.length - 1);
        cellEnd1.setCellValue(DateUtil.getNow());

        try {
            output = new ByteArrayOutputStream();
            wb.write(output);
            inputStream1 = new ByteArrayInputStream(output.toByteArray());
            output.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                if (output != null) {
                    output.close();
                    if (inputStream1 != null) {
                        inputStream1.close();
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return inputStream1;
    }

    private void setCellVal(Object j, CellStyle content, SXSSFCell cell) {
        cell.setCellValue(j.toString());
        cell.setCellStyle(content);
    }


    private DsstoreBillDelivery convertToDsstoreBillRice(JSONObject jsonObject) {
        DsstoreBillDelivery DsstoreBillRice = new DsstoreBillDelivery();
        DsstoreBillRice.setBillNo(jsonObject.getOrDefault("BillNO", "").toString());
        DsstoreBillRice.setOtherSideName(jsonObject.getOrDefault("OtherSideName", "").toString());
        DsstoreBillRice.setShopName(jsonObject.getOrDefault("ShopName", "").toString());
        DsstoreBillRice.setItemBigClassName(jsonObject.getOrDefault("ItemBigClassName", "").toString());
        DsstoreBillRice.setItemAssistNo(jsonObject.getOrDefault("ItemAssistNO", "").toString());
        DsstoreBillRice.setItemSpec(jsonObject.getOrDefault("ItemSpec", "").toString());
        DsstoreBillRice.setSellTaxes(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("SellTaxes", "").toString()));
        DsstoreBillRice.setItemSmallClassCode(jsonObject.getOrDefault("ItemSmallClassCode", "").toString());
        DsstoreBillRice.setArriveMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("ArriveMoney", "").toString()));
        DsstoreBillRice.setStoreCode(jsonObject.getOrDefault("StoreCode", "").toString());
        DsstoreBillRice.setOutputRate(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("outputRate", "").toString()));
        DsstoreBillRice.setStoreBillRemark(jsonObject.getOrDefault("StoreBillRemark", "").toString());
        DsstoreBillRice.setOutMainAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("OutMainAmount", "").toString()));
        DsstoreBillRice.setItemSign(jsonObject.getOrDefault("ItemSign", "").toString());
        DsstoreBillRice.setShopCode(jsonObject.getOrDefault("ShopCode", "").toString());
        DsstoreBillRice.setTaxMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("TaxMoney", "").toString()));
        DsstoreBillRice.setStoreBillDtid(jsonObject.getOrDefault("StoreBillDTID", "").toString());
        DsstoreBillRice.setModifyDate(ConvertUtil.convertToDate(jsonObject.getOrDefault("modifyDate", "").toString()));
        DsstoreBillRice.setStoreName(jsonObject.getOrDefault("StoreName", "").toString());
        DsstoreBillRice.setStoreBillidRemark(jsonObject.getOrDefault("StoreBillIDRemark", "").toString());
        DsstoreBillRice.setMainUnit(jsonObject.getOrDefault("MainUnit", "").toString());
        DsstoreBillRice.setGiftFlag(ConvertUtil.convertBooleanToInt(jsonObject.getOrDefault("GiftFlag", "").toString()));
        DsstoreBillRice.setOutStoreMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("OutStoreMoney", "").toString()));
        DsstoreBillRice.setItemId(jsonObject.getOrDefault("ItemID", "").toString());
        DsstoreBillRice.setItemSmallClassName(jsonObject.getOrDefault("ItemSmallClassName", "").toString());
        DsstoreBillRice.setStoreBillReState(ConvertUtil.convertBooleanToInt(jsonObject.getOrDefault("StoreBillReState", "").toString()));
        DsstoreBillRice.setBusUser(jsonObject.getOrDefault("BusUser", "").toString());
        DsstoreBillRice.setTaxes(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("Taxes", "").toString()));
        DsstoreBillRice.setBatchCode(jsonObject.getOrDefault("BatchCode", "").toString());
        DsstoreBillRice.setInStoreMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("InStoreMoney", "").toString()));
        DsstoreBillRice.setIsOut(ConvertUtil.convertToInt(jsonObject.getOrDefault("isOut", "").toString()));
        DsstoreBillRice.setShopId(jsonObject.getOrDefault("ShopID", "").toString());
        DsstoreBillRice.setMakeTime(ConvertUtil.convertToDate(jsonObject.getOrDefault("MakeTime", "").toString()));
        DsstoreBillRice.setBillBusType(jsonObject.getOrDefault("BillBusType", "").toString());
        DsstoreBillRice.setProcessMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("processMoney", "").toString()));
        DsstoreBillRice.setItemCode(jsonObject.getOrDefault("ItemCode", "").toString());
        DsstoreBillRice.setPushOutStoreMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("PushOutStoreMoney", "").toString()));
        DsstoreBillRice.setInMainAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("InMainAmount", "").toString()));
        DsstoreBillRice.setPushOutStoreAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("PushOutStoreAmount", "").toString()));
        DsstoreBillRice.setStoreBillId(jsonObject.getOrDefault("StoreBillID", "").toString());
        DsstoreBillRice.setSellIncludeTaxMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("SellIncludeTaxMoney", "").toString()));
        DsstoreBillRice.setOutBusAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("OutBusAmount", "").toString()));
        DsstoreBillRice.setOtherSideType(jsonObject.getOrDefault("OtherSideType", "").toString());
        DsstoreBillRice.setPushInStoreMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("PushInStoreMoney", "").toString()));
        DsstoreBillRice.setYield(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("yield", "").toString()));
        DsstoreBillRice.setArriveAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("ArriveAmount", "").toString()));
        DsstoreBillRice.setItemName(jsonObject.getOrDefault("ItemName", "").toString());
        DsstoreBillRice.setSysBatchCode(jsonObject.getOrDefault("SysBatchCode", "").toString());
        DsstoreBillRice.setCreateDate(ConvertUtil.convertToDate(jsonObject.getOrDefault("createDate", "").toString()));
        DsstoreBillRice.setAuditDate(ConvertUtil.convertToDate(jsonObject.getOrDefault("auditDate", "").toString()));
        DsstoreBillRice.setOtherSideId(jsonObject.getOrDefault("OtherSideID", "").toString());
        DsstoreBillRice.setBillType(jsonObject.getOrDefault("BillType", "").toString());
        DsstoreBillRice.setSellTaxMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("SellTaxMoney", "").toString()));
        DsstoreBillRice.setBillBusTypeId(jsonObject.getOrDefault("BillBusTypeId", "").toString());
        DsstoreBillRice.setPushInStoreAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("PushInStoreAmount", "").toString()));
        DsstoreBillRice.setInBusAmount(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("InBusAmount", "").toString()));
        DsstoreBillRice.setBusDate(ConvertUtil.convertToDate(jsonObject.getOrDefault("busDate", "").toString()));
        DsstoreBillRice.setAPYear(ConvertUtil.convertToLong(jsonObject.getOrDefault("APYear", "").toString()));
        DsstoreBillRice.setItemBigClassCode(jsonObject.getOrDefault("ItemBigClassCode", "").toString());
        DsstoreBillRice.setSaleMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("SaleMoney", "").toString()));
        DsstoreBillRice.setStoreId(jsonObject.getOrDefault("StoreID", "").toString());
        DsstoreBillRice.setItemAbc(jsonObject.getOrDefault("ItemAbc", "").toString());
        DsstoreBillRice.setArrivalDate(ConvertUtil.convertToDate(jsonObject.getOrDefault("ArrivalDate", "").toString()));
        DsstoreBillRice.setAPMonth(ConvertUtil.convertToInt(jsonObject.getOrDefault("APMonth", "").toString()));
        DsstoreBillRice.setOtherSideCode(jsonObject.getOrDefault("OtherSideCode", "").toString());
        DsstoreBillRice.setBusUnit(jsonObject.getOrDefault("BusUnit", "").toString());
        DsstoreBillRice.setIncludeTaxMoney(ConvertUtil.convertToDecimal(jsonObject.getOrDefault("IncludeTaxMoney", "").toString()));
        DsstoreBillRice.setParentBillNo(jsonObject.getOrDefault("ParentBillNO", "").toString());
        return DsstoreBillRice;
    }
}
